<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            资源类型：

                            <select id="type" name="type">
                                <option th:each="dict : ${resourcesTypeList}" th:text="${dict['name']}"
                                        th:value="${dict['type']}" th:field="*{resourcesType.type}"></option>
                            </select>

                        </li>
                        <li>
                            数据名称：<input type="text" name="name"/>
                        </li>

                        <li>
                            数据状态：
                            <select name="status" th:with="type=${@dict.getType('sys_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" th:onclick="$.operate.add([[${resourcesType.type}]])">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:resourcesData:edit">
                <i class="fa fa-edit"></i> 修改
            </a>


        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:src="@{/ajax/libs/select/select2.js}"></script>
<script th:inline="javascript">
    var editFlag = "";
    var removeFlag = "";
    var prefix = ctx + "system/resourcesData";
    var datas = [[${@dict.getType('sys_status')}]];
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            queryParams: queryParams,
            modalName: "资源数据",
            sortName: "dataSort",
            sortOrder: "asc",
            search: false,
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '数据名称',
                    align: 'center',
                    sortable: true
                },
                {
                    field: 'linkUrl',
                    title: '链接地址',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if(row.linkUrl!=""||row.linkUrl!=null||row.linkUrl!=undefined){
                            return '<a href="#" onclick="detail(\'' + value + '\')">' + value + '</a>';
                        }
                        else {
                            return "-";
                        }
                    }
                },
                {
                    field: 'url',
                    title: '数据地址',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if(row.url!=""||row.url!=null||row.url!=undefined){
                            return '<a href="#" onclick="detail(\'' + value + '\')">' + value + '</a>';
                        }else {
                            return "-";
                        }


                    }
                },
                {
                    field: 'dataSort',
                    title: '数据排序',
                    align: 'center',
                    sortable: true
                },
                {
                    field: 'type',
                    title: '数据类型',
                    align: 'center',
                    sortable: true
                },
                {
                    field: 'status',
                    title: '数据状态',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'createBy',
                    title: '创建人',
                    align: 'center',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: 'center',
                    sortable: true
                },
                {
                    field: 'updateBy',
                    title: '更新人',
                    align: 'center',
                    sortable: true
                },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    align: 'center',
                    sortable: true
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        return {
            type: $("#type").val(),
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            searchValue: params.search,
            orderByColumn: params.sort,
            isAsc: params.order
        };
    }

    function detail(value) {
        window.open(value)
    }
</script>

</body>
</html>